<?php
include_once("./_common.php");

$store_name = $_POST['a']; //지점
$name_name = $_POST['b']; //방문자

if($store_name == "all" && $name_name == "all") {
	$sql0 = "select count(*) as cnt from visit_record";
} else if ($store_name == "all" && $name_name != "all") {
	$sql0 = "select count(*) as cnt from visit_record where vi_name1 = '$name_name'";
} else if ($store_name != "all" && $name_name == "all") {
	$sql0 = "select count(*) as cnt from visit_record where vi_store = '$store_name'";
} else {
	$sql0 = "select count(*) as cnt from visit_record where vi_store = '$store_name' AND vi_name1 = '$name_name'";
}
$row0 = sql_fetch($sql0);
$total_count = $row0['cnt'];

$rows = 10;
$total_page = ceil($total_count / $rows);
if ($page == "") $page = 1;
$from_record = ($page -1) * $rows;

$sql1 = "select * from visit_record limit $from_record, $rows ";
$result = sql_query($sql1);
$pagelist = get_paging2($rows, $page, $total_page, "/adm/m_visit_list.php?$qstr&page=");

if($store_name == "all" && $name_name == "all") {
	$sql = "select * from visit_record order by id DESC limit $from_record, $rows";
} else if ($store_name == "all" && $name_name != "all") {
	$sql = "select * from visit_record where vi_name1 = '$name_name' order by id DESC limit $from_record, $rows";
} else if ($store_name != "all" && $name_name == "all") {
	$sql = "select * from visit_record where vi_store = '$store_name' order by id DESC limit $from_record, $rows";
} else {
	$sql = "select * from visit_record where vi_store = '$store_name' AND vi_name1 = '$name_name' order by id DESC limit $from_record, $rows";
}
$rst = sql_query($sql);
while($row = mysql_fetch_assoc($rst)) {
	$li[] = $row;
}
?>
<style>
table.p_t {width:100%}
table.p_t tr {line-height:24px;}
table.p_t th {background:url(/test/manage/imgs/tit_bg.gif) repeat-x;height:38px;color:white;line-height:16px;font-weight:normal;}
table.p_t th {border-bottom:1px solid #CCCCCC}
table.p_t td {border-bottom:none;}
table.p_t td {text-align:center;height:30px;}
table.p_t td a {color:black}
.mb15 {margin-bottom:15px;}

</style>
<table class="p_t" cellpadding="0" cellspacing="0">
	<tr>
	<th></th>
	<th>방문일자</th>
	<th>구분</th>
	<th>방문자</th>
	<th>점명</th>
	<th>점주명</th>
	</tr>
	<?php
	if(count($li) == "0") { ?>
		<tr><td colspan="6" align="center">방문일지가 없습니다.</td></tr>
	<?php
	} else {
		for($i = 0; $i < count($li); $i += 1) {
	?>
		<tr>
		<td><?php// echo count($li) - $i;?></td>
		<td><a href="<?php echo $g4['path']?>/adm/m_visit_view.php?id=<?php echo $li[$i]['id']?>"><?php echo $li[$i]['vi_date']?></a></td>
		<td><?php echo $li[$i]['vi_flag']?></td>
		<td><?php echo $li[$i]['vi_name1']?></td>
		<td><?php echo $li[$i]['vi_store']?></td>
		<td><?php echo $li[$i]['vi_name2']?></td>
		</tr>
		<tr style="height:1px;background-color:#d9d9d9"><td colspan="13" style="height:1px;"></td></tr>
	<? } ?>
<? } ?>
</table>

<br />
<style>
	div.jj_btnwrap {position:relative;height:35px;width:100%}
	div.jj_btn_subwrap {overflow:hidden;position:absolute;top:0;right:0}
	div.jj_btnwrap div {float:left;margin-left:7px}
	div.jj_btn_box_on {width:35px;height:35px;border:1px solid #ccc;background-color:#fbf8ee}
	div.jj_btn_box_off {width:35px;height:35px;border:1px solid #ccc;}
	p.jj_on_font {vertical-align:middle;padding:0;margin:0;font-weight:bold;color:black;font-size:13px;margin-top:8px;}
	p.jj_off_font {vertical-align:middle;padding:0;margin:0;font-weight:bold;color:#666;font-size:13px;margin-top:8px;}
	</style>

	<div class="jj_btnwrap">
		<div class="jj_btn_subwrap">
			<?php echo $pagelist;?>
		</div>
	</div>

<script>
$("#cl_jj_bt_hide").hide();
</script>